// TOWN SCRIPT
//    Town 0: Under Hatherond

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
// This state called whenever this town is entered.
		set_state_continue(39);
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 12;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
		flip_terrain(23,17);
		set_state_continue(13);
		}
break;

beginstate 13;
	if (get_terrain(18,19) == 0)
		set_state_continue(19);
	set_state_continue(20);
break;

beginstate 15;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
		flip_terrain(10,14);
		set_state_continue(16);
		}
break;

beginstate 16;
	if (get_terrain(19,13) == 0)
		set_state_continue(17);
	set_state_continue(18);
break;

beginstate 17;
	set_terrain(19,13,299);
break;

beginstate 18;
	set_terrain(19,13,0);
break;

beginstate 19;
	set_terrain(18,19,298);
break;

beginstate 20;
	set_terrain(18,19,0);
break;

beginstate 21;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
                flip_terrain(18,6);
                }
break;

beginstate 22;
	flip_terrain(34,34);
break;

beginstate 23;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
                flip_terrain(20,6);
                }
break;

beginstate 24;
	reset_dialog();
	add_dialog_str(0,"The manual here dictates the usage of the three levers to the north. Or at least it used to: many of the pages have been damaged beyond reading possibilities. You are able to cull some useful information from it, though.",0);
	add_dialog_str(1,"It seems that lever settings are dictated in gerompels and zkals. Gerompels are either one when the lever points east and two when it points west. The gerompel of the lever is multiplied by the zkal, which is _indicated elsewhere_.",0);
	add_dialog_str(2,"There's a brief listing of relevant products of all gerompel-zkals. A recent addition in red catches your eye. It reads: _Storeroom - 5733._",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
break;

beginstate 25;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
                flip_terrain(22,6);
                }
break;

beginstate 27;
	reset_dialog_preset_options(2);
	choice = run_dialog(0);
	if (choice == 2) {
		set_state_continue(28);
		}
break;

beginstate 28;
     if (get_terrain(18,6) == 374)
		set_state_continue(29);
	set_state_continue(34);
break;

beginstate 29;
        if (get_terrain(20,6) == 374)
		set_state_continue(30);
	set_state_continue(34);
break;

beginstate 30;
        if (get_terrain(22,6) == 375)
		set_state_continue(31);
	set_state_continue(34);
break;

beginstate 31;
	if (get_terrain(33,36) == 0)
		set_state_continue(32);
	set_state_continue(33);
break;

beginstate 32;
	flip_terrain(34,34);
	set_terrain(33,36,299);
break;

beginstate 33;
	flip_terrain(34,34);
	set_terrain(33,36,0);
break;

beginstate 34;
	message_dialog("The lever clicks forward. Then it slides back. Nothing happens.","");
	block_entry(1);
	set_state_continue(22);
break;

beginstate 35;
	block_entry(1);
	reset_dialog_preset_options(5);
	choice = run_dialog(0);
	if (choice == 2) {
		move_to_new_town(1,20,23);
		end();
		}
break;

beginstate 36;
	block_entry(1);
	reset_dialog_preset_options(5);
	choice = run_dialog(0);
	if (choice == 2) {
                move_to_new_town(1,49,13);
		end();
		}
break;

beginstate 37;
		put_item_on_spot(26,33,306);
break;

beginstate 38;
	if (get_flag(80,6) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"The fact that a city like Hatherond even has underground sewers in the first place is indicative of its prosperity. On the other hand, they aren't very well maintained at all, infested with large rodents and other vermin.",0);
	add_dialog_str(1,"The weak sound of the dripping of water pales against the constant shuffle and chittering of the beasts that inhabit the sewers. A dangerous task lies ahead for you.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(80,6,250);
break;

beginstate 39;
	if (get_flag(100,0) >= 2)
		set_state_continue(38);
break;

beginstate 40;
     if (get_terrain(33,36) == 0)
	     set_terrain(33,36,299);
break;